<?php require_once('../connections/con_gl.php'); ?>
<?php
$t = $_GET['t'];
$q = $_GET['q'];
$n = $_GET['noref'];
$r = intval($_GET['replace']);
if($n <>'') {
	// get order
	mysql_select_db($database_con_gl, $con_gl);
	$query_gkend = "select kendaraan from gl_trans where no_ref='$n' AND kendaraan <>''";
	$gken  = mysql_query($query_gkend, $con_gl) or die(mysql_error());
	$row_gken = mysql_fetch_assoc($gken);
	$totalRows_gkend = mysql_num_rows($gkend);
	if($totalRows_gkend > 0) { 
	$where_kend = "";
		$i = 1; 
		do {
			$where_kend .="(";
			$where_kend .= "nopolisi=".$row_gkend['kendaraan'];
			if($i<$totalRows_gkend - 1) {
				$where_kend .= " OR ";	
			}else{
				$where_kend .=")";	
			}
		$i++;
		}while($row_gkend = mysql_fetch_assoc($gken));
	}
}
// get kendaraan
mysql_select_db($database_con_gl, $con_gl);
$query_kend = "SELECT a.nopolisi, a.tahun, b.tipekendaraan, a.tersedia, a.keterangan from gl_masterkendaraan a, gl_tipekendaraan b, gl_ where a.jeniskendaraan = b.id and a.nopolisi=";
if($t<>'2') { 
	$query_kend .=" AND a.tersedia='$t'";
}
if($where_kend<>'') {
	$query_kend .= " AND ".$where_kend;
}
$query_kend .=" AND (a.nopolisi LIKE '%$q%' OR b.tipekendaraan LIKE '%$q%') order by b.tipekendaraan, a.nopolisi asc";
$kend = mysql_query($query_kend, $con_gl) or die(mysql_error());
$row_kend = mysql_fetch_assoc($kend);
$totalRows_kend = mysql_num_rows($kend);
?>
<select name="kendaraan" id="kendaraan">
<option value="">Pilih Kendaraan</option>
<?php if($totalRows_kend > 0) { do { ?>
<option value="<?php echo $row_kend['nopolisi'];?>"><?php echo $row_kend['tipekendaraan'];?> - ( <?php echo $row_kend['nopolisi'];?> )</option>
<?php }while($row_kend = mysql_fetch_assoc($kend)); } ?>
</select>
